package priv.lirenhe.dissertation.component.data_parser.data_parser_executor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import priv.lirenhe.dissertation.component.data_parser.content_parser.WebContentToTextParser;
import priv.lirenhe.dissertation.component.data_parser.url_parser.WebContentToUrlParser;

public class DataParserExecutor {
	private String webContent;
	private String realUrl;
	
	public DataParserExecutor(String realUrl,String webContent){
		this.webContent = webContent;
		this.realUrl = realUrl;
	}
	
	/**
	 * map中的value可以为null
	 * @return
	 */
	public Map<Object,Object> getDataAfterParser(){
		Map<Object,Object> dataAfterParser = null;
		
		try{
			if(realUrl != null && webContent != null){
				dataAfterParser = new HashMap<Object,Object>();
				String webContentInText = null;
				String webTitle = null;
				
				WebContentToUrlParser webContentToUrlParser = new WebContentToUrlParser(this.webContent);
				List<String> urlOfList = webContentToUrlParser.getUrlOfList(this.realUrl);
				dataAfterParser.put("urlOfList", urlOfList);
				
				WebContentToTextParser webContentToTextParser = new WebContentToTextParser(this.webContent);
				webContentInText = webContentToTextParser.getContentInText();
				dataAfterParser.put("webContentInText", webContentInText);
				
				webTitle = webContentToTextParser.getContentTitle();
				dataAfterParser.put("webTitle", webTitle);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return dataAfterParser;
	}
	
	public static void main(String[] args) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("01", null);
		System.out.println(map.get("01"));
	}
}
